﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using migradorWPF.ViewModels;
using FolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog;
using dialogResult = System.Windows.Forms.DialogResult;

namespace migradorWPF
{
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MainWindowsViewModel();
        }

        private void btnSeleccionarDirParches_Click(object sender, RoutedEventArgs e)
        {
            if (GetViewModel().BaseDeDatos.AplicandoParches)
            {
                System.Windows.MessageBox.Show("Se esta ejecutando una operación actualmente");
                return;
            }

            FolderBrowserDialog dialogSeleccionarDirParches = new FolderBrowserDialog();

            dialogResult result = dialogSeleccionarDirParches.ShowDialog();
            if (result.Equals(dialogResult.OK))
            {
                string folderName = dialogSeleccionarDirParches.SelectedPath;
                txtDirParches.Text = folderName;
                GetViewModel().PathDirParches = folderName;
                GetViewModel().LeerDirectorioParches();
            }
        }

        private MainWindowsViewModel GetViewModel()
        {
            return this.DataContext as MainWindowsViewModel;
        }

        private void btnLimparConsola_Click(object sender, RoutedEventArgs e)
        {
            GetViewModel().LogSalidaPantalla = String.Empty;
        }

        private void chkProcedimientosAlmacenados_Click(object sender, RoutedEventArgs e)
        {
            GetViewModel().BorrarDatosParches();
        }

    }
}
